﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace ClientRegister
{
    public partial class Login : Form
    {
        public Login()
        {
            InitializeComponent();
            Application.Exit();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            int role = 0;

            if (txtID.Text == "" || txtPassword.Text == "")
            {
                MessageBox.Show("Vui lòng nhập đầy đủ ID và Password");
                txtID.Focus();
                return;
            }
            else
            {
                int id = int.Parse(txtID.Text.ToString());
                string pass = txtPassword.Text;

                SqlConnection con = new SqlConnection(@"Data Source=NHAT-PC;Initial Catalog=RegisterDB;Integrated Security=True");
                con.Open();
                SqlCommand cmd = new SqlCommand("Select IDRole from Employees where ID = "+id+" and Password = '"+pass+"'",con);
                SqlDataReader reader = cmd.ExecuteReader();
                if(reader.Read())
                    role = int.Parse(reader.GetValue(0).ToString());
                con.Close();
            }
            
            switch (role)
            {
                case 1:
                    NhanVienQuanTri nvqtform = new NhanVienQuanTri();
                    nvqtform.Show();
                    this.Hide();
                    break;

                case 2:
                    NhanvienDK nvdkform = new NhanvienDK();
                    nvdkform.Show();
                    this.Hide();
                    break;

                case 3:
                    NhanVienGiaoVu nvgvform = new NhanVienGiaoVu();
                    nvgvform.Show();
                    this.Hide();
                    break;
                default:
                    MessageBox.Show("ID hoặc Password không đúng. Vui lòng nhập lại");
                    break;
            }
        }
    }
}
